1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class GameManager : MonoBehaviour {
6
7     
public static int PlayerScore1 = 0;
8     
public static int PlayerScore2 = 0;
9
10     
public GUISkin layout;
11
12     GameObject theBall;
13
14     
// Use this for initialization
15     
void Start () {
16         theBall = GameObject.FindGameObjectWithTag (
"Ball");
17     }
18
19     
public static void Score(string wallID) {
20         
if (wallID == "RightWall") {
21             PlayerScore1++;
22         }
else {
23             PlayerScore2++;
24         }
25     }
26
27     
void OnGUI() {
28         GUI.skin = layout;
29         GUI.Label (
new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "" + PlayerScore1);
30         GUI.Label (
new Rect (Screen.width / 2 + 150 + 12, 20, 100, 100), "" + PlayerScore2);
31
32         
if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESTART")) {
33             PlayerScore1 =
0;
34             PlayerScore2 =
0;
35             theBall.SendMessage (
"RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
36         }
37
38         
if (PlayerScore1 == 10) {
39             GUI.Label (
new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER ONE WINS");
40             theBall.SendMessage (
"ResetBall", null, SendMessageOptions.RequireReceiver);
41         }
else if (PlayerScore2 == 10) {
42             GUI.Label (
new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
43             theBall.SendMessage (
"ResetBall", null, SendMessageOptions.RequireReceiver);
44         }
45     }
46
47 }


Use this for initialization



Gõ tìm kiếm nhanh...